<?php
// +----------------------------------------------------------------------
// | 07FLYSAAS [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2025-2035 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------


namespace app\plat\model;

/**
 * 岗位模型
 */
class TenPosition extends PlatBase
{
    /**
     * 获得所有指定id所有父级
     * @param int $deptid
     * @param array $data
     * @return array
     */
    public function getTenPositionAllPid($deptid = 0, $data = [])
    {
        $where['id'] = ['=', $deptid];
        $info = $this->modelTenPosition->getInfo($where, 'id,pid');
        if (!empty($info) && $info['pid']) {
            $data[] = $info['pid'];
            return $this->getTenPositionAllPid($info['pid'], $data);
        }
        return $data;
    }

    /**
     * 获得所有指定id所有子级
     * @param int $deptid
     * @param array $data
     * @return array
     */
    public function getTenPositionAllSon($deptid = 0, $data = [])
    {
        $where['pid'] = ['=', $deptid];
        $sons = $this->modelTenPosition->getList($where, 'id', 'sort asc', false);
        if (count($sons) > 0) {
            foreach ($sons as $v) {
                $data[] = $v['id'];
                $data = $this->getTenPositionAllSon($v['id'], $data); //注意写$data 返回给上级
            }
        }
        if (count($data) > 0) {
            return $data;
        } else {
            return false;
        }
        return $data;
    }
}
